class TopicTagLib {
    def authenticateService

    def topicStatus = { attrs ->
        def topic = attrs.topic
        if(topic.status == 'END') {
            out << "<a href='show/${topic.id}' alt='${topic.name}'>话题结束啦</a>"
        } else if(topic.status == 'START') {
            out << "<a href='show/${topic.id}' alt='${topic.name}'>看看</a>"
        } else if(topic.status == 'INIT') {
            if(authenticateService.isLoggedIn()) {
                def topicUser = TopicUser.findByUserAndTopic(authenticateService.userDomain(), topic)
                
                if(topicUser?.role == 'speaker') {
                    out << "<a href='show/${topic.id}' alt='${topic.name}'>已参与发言</a>"
                } else if(topicUser?.role == 'owner'){
                    out << "<a href='show/${topic.id}' alt='${topic.name}'>您的话题</a>"
                } else if(topicUser?.role == 'viewer'){
                    out << "<a href='show/${topic.id}' alt='${topic.name}'>您是观众</a>"
                } else {
                    out << "<a href='joinAsSpeaker/${topic.id}' alt='${topic.name}'>发言</a>"
                    out << " | "
                    out << "<a href='joinAsViewer/${topic.id}' alt='${topic.name}'>观众</a>"
                }
            } else {
                out << "<a href='joinAsSpeaker/${topic.id}' alt='${topic.name}'>发言</a>"
                out << " | "
                out << "<a href='joinAsViewer/${topic.id}' alt='${topic.name}'>观众</a>"
            }
        }
    }
}
